<template>
	<view>
		<u-navbar :is-back="true" :title="title"></u-navbar>
		<view class="question-answer-box">
			<u-empty text="暂无提问" mode="list" v-if="isnull1()" icon-size="80" margin-top="200"></u-empty>
			<block v-for="(questionslist,findex) in gfquestions" :key="findex">
				<view class="example animation-slide-bottom" v-for="(item,index) in questionslist"
					@click="godetail(item,index,'guanfang',findex)">
					<view class="qes">
						<image src="@/static/img/sign-question.png" mode="widthFix" style="width: 32rpx;">
						</image>
						{{item.content}}
					</view>
					<view class="ans">
						<image src="@/static/img/sign-answer.png" mode="widthFix" style="width: 32rpx;">
						</image>
						{{item.detail?item.detail.content:"暂无回答"}}
					</view>
					<view
						style="display: flex;justify-content: flex-end;padding: 20rpx;width: 100%;text-align: right;font-size: 22rpx;padding-bottom:0"
						class="text-gray ">
						<view style="margin-right: 10rpx;">问题发布于{{getTimeFormat(item.createTime)}}</view>
						<u-icon name="eye" color="#2979ff" size="32"></u-icon>
						<view style="margin-left: 5rpx;font-size: 28rpx;">{{item.chakannum?item.chakannum:0}}</view>
						
					</view>
				</view>
			</block>

		</view>
	</view>
</template>

<script>
	import {
		getGoodsCollection,
		deleteGoodsCollection,
		deleteStoreCollection,
	} from "@/api/members.js";
	import {
		http,
		Method
	} from "@/utils/request.js";
	import storage from "@/utils/storage.js";
	import moment from 'dayjs';

	export default {
		data() {
			return {
				title: "",
				id: null,
				glpage: 1,
				pageSize: 20,
				gfquestions: [],
				gftotal: 0,
			}
		},
		onLoad(options) {
			this.title = options.title;
			this.id = options.id;
			this.dataList1();
		},
		methods: {
			godetail(item, index, type, findex) {
				if (type == "feiguanfang") {
					if (!this.questions[findex][index]["chakannum"]) {
						this.questions[findex][index]["chakannum"] = 1
					} else {
						this.questions[findex][index]["chakannum"] = this.questions[findex][index]["chakannum"] + 1
					}
				} else if (type == "guanfang") {
					if (!this.gfquestions[findex][index]["chakannum"]) {
						this.gfquestions[findex][index]["chakannum"] = 1
					} else {
						this.gfquestions[findex][index]["chakannum"] = this.gfquestions[findex][index]["chakannum"] + 1
					}
				}
				this.$forceUpdate()
				uni.navigateTo({
					url: "/pages/verticalnav/question-detail?id=" + item.id,
				})
			},
			getTimeFormat(timeLong) {
			
				let now = moment()
				let time = moment(timeLong);
				let minute = now.diff(time, "minute");
				let hour = now.diff(time, "hour");
				let day = now.diff(time, "day");
				// if(day==0 && hour==0 && minute<=60){
				// 	return minute+"分钟前"
				// }
				// if(day==0 && hour<=24){
				// 	return hour+"小时"+minute+"分钟前";
				// }
				// if(day<=30){
				// 	return day+"天"+hour+"小时"+minute+"分钟前"
				// }
				return time.format("YYYY-MM-DD HH:mm");
			},
			isnull1() {
				let questions = this.gfquestions;
				if (questions.length == 0) {
					return true;
				} else {
					if (questions[0].length == 0) {
						return true;
					}
				}
				return false;
			},
			async dataList1() {
				let user = storage.getUserInfo();
				let params = {
					pageNumber: this.glpage,
					pageSize: this.pageSize,
					deleteFlag: false,
					sort: "create_time",
					order: "desc",
					industryId: this.id,
					createBy: "SYSTEM"
				}

				uni.showLoading({
					title: "加载中",
					mask: true
				})
				let res = await http.request({
					url: "/lili/liQuestions",
					method: Method.GET,
					needToken: true,
					params,
				});

				let data = res.data.result.records || [];
				this.gftotal = res.data.result.total;
				let index = this.glpage - 1;
				this.gfquestions[index] = data;
				this.$forceUpdate()
				uni.hideLoading()
				console.log("showHangyeList", this.questions)
			},
		}
	}
</script>

<style scoped lang="scss">
	.question-answer-box {
		padding: 0 30rpx;
		.example {
			font-size: 26rpx;
			margin-bottom: 30rpx;

			image {
				width: 32rpx;
				height: 32rpx;
				position: relative;
				top: 8rpx;
				margin-right: 15rpx;
			}

			.qes {
				font-size: 28rpx;
				font-weight: 550;
				padding: 30rpx 0 10rpx;
				line-height: 50rpx;
			}
		}
	}
</style>
